<html>
<head><meta charset="utf-8"><title>const eval tests may get propagated away · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20eval.20tests.20may.20get.20propagated.20away.html">const eval tests may get propagated away</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="167655728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20eval%20tests%20may%20get%20propagated%20away/near/167655728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20eval.20tests.20may.20get.20propagated.20away.html#167655728">(Jun 08 2019 at 15:34)</a>:</h4>
<p>We have a bunch of tests in our test suite that compare the result of a compile-time evaluation (so a constant) against a runtime evaluation. The problem is that <span class="user-mention" data-user-id="125250">@Wesley Wiser</span>  is making our const propagator way too smart for its own good. It will at some point be able to optimize the right hand side of a <code>C == foo(42)</code> comparison to a constant, and then optimize away the entire comparison. Now we can easily prevent this by wrapping the <code>foo(42)</code> in a call to <code>test::black_box</code>, but then the call will still get optimized, so we wrap the <code>42</code>, too and then we end up with <code>b(foo(b(42)))</code>, which isn't too bad, but its very error-prone.</p>



<a name="167655792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20eval%20tests%20may%20get%20propagated%20away/near/167655792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20eval.20tests.20may.20get.20propagated.20away.html#167655792">(Jun 08 2019 at 15:36)</a>:</h4>
<p>In order to make these tests a little saner, we could create a <code>rustc_*</code> attribute that makes const prop not run for the entire crate or maybe just function or even specific statements in the function.</p>



<a name="167655914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20eval%20tests%20may%20get%20propagated%20away/near/167655914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20eval.20tests.20may.20get.20propagated.20away.html#167655914">(Jun 08 2019 at 15:40)</a>:</h4>
<p>A PR where this came up: <a href="https://github.com/rust-lang/rust/pull/61658" target="_blank" title="https://github.com/rust-lang/rust/pull/61658">https://github.com/rust-lang/rust/pull/61658</a></p>



<a name="167666568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20eval%20tests%20may%20get%20propagated%20away/near/167666568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20eval.20tests.20may.20get.20propagated.20away.html#167666568">(Jun 08 2019 at 20:35)</a>:</h4>
<p>would it be possible to write a macro for this end?</p>



<a name="167666630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20eval%20tests%20may%20get%20propagated%20away/near/167666630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20eval.20tests.20may.20get.20propagated.20away.html#167666630">(Jun 08 2019 at 20:36)</a>:</h4>
<p>that somehow <code>non_eval!(foo(42))</code> expanded to <code>b(foo(b(42))</code>?</p>



<a name="167666644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20eval%20tests%20may%20get%20propagated%20away/near/167666644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20eval.20tests.20may.20get.20propagated.20away.html#167666644">(Jun 08 2019 at 20:37)</a>:</h4>
<p>maybe, but I still fear we'll end up missing edge cases</p>



<a name="167666646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20eval%20tests%20may%20get%20propagated%20away/near/167666646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20eval.20tests.20may.20get.20propagated.20away.html#167666646">(Jun 08 2019 at 20:37)</a>:</h4>
<p>like we'll have to think about all cases</p>



<a name="167666648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20eval%20tests%20may%20get%20propagated%20away/near/167666648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20eval.20tests.20may.20get.20propagated.20away.html#167666648">(Jun 08 2019 at 20:37)</a>:</h4>
<p>the attribute system will "just work"</p>



<a name="167666704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const%20eval%20tests%20may%20get%20propagated%20away/near/167666704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const.20eval.20tests.20may.20get.20propagated.20away.html#167666704">(Jun 08 2019 at 20:38)</a>:</h4>
<p>hmmm ok</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>